package com.gosling.cloudspace.controller;


import com.gosling.cloudspace.common.annotation.JwtIgnore;
import com.gosling.cloudspace.common.entity.dtos.LoginDto;
import com.gosling.cloudspace.common.entity.pojo.UserInfoPO;
import com.gosling.cloudspace.common.entity.vo.LoginResultVO;
import com.gosling.cloudspace.common.entity.vo.UserInfoReqVO;
import com.gosling.cloudspace.common.entity.vo.UserInfoVO;
import com.gosling.cloudspace.common.service.UserInfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.List;

/**
 * 登录控制器
 *
 * @email 1793327033@qq.com
 * @classname UserLoginController
 * @author: osc_lihonglin
 * @date: 2021/6/24 9:50
 */
@Slf4j
@JwtIgnore
@CrossOrigin
@RestController
@RequestMapping("/user/login")
public class UserInfoController {

    @Resource
    private UserInfoService userLoginService;

    /**
     * 登录
     *
     * @param dto
     * @return
     */
    @JwtIgnore
    @RequestMapping("/in")
    public LoginResultVO login(HttpServletRequest request, @RequestBody LoginDto dto) {
        return userLoginService.login(request, dto);
    }

    /**
     * 获取当前登录用户信息
     *
     * @return
     */
    @GetMapping("/localUserInfo")
    public UserInfoVO getLoginUser() {
        return userLoginService.localUserInfo();
    }

    /**
     * 获取用户信息
     *
     * @return
     */
    @RequestMapping("/getUserInfoByUserId")
    public UserInfoVO getUserInfo(@Valid @RequestBody UserInfoReqVO vo) {
        return userLoginService.getUserInfo(vo);
    }

    /**
     * 获取所有用户信息
     *
     * @return
     */
    @RequestMapping("/getUserInfoAll")
    public List<UserInfoVO> getUserInfoAll() {
        return userLoginService.getUserInfoAll();
    }

    /**
     * 注册
     *
     * @param dto
     * @return
     */
    @JwtIgnore
    @RequestMapping("/registry")
    public void registry(HttpServletRequest request, @RequestBody LoginDto dto) {
        userLoginService.registry(request, dto);
    }

    /**
     * 注销
     *
     * @return
     */
    @JwtIgnore
    @RequestMapping("/logout")
    public void logout() {
        userLoginService.logout();
    }

    /**
     * 退出
     *
     * @return
     */
    @JwtIgnore
    @RequestMapping("/offline")
    public void offline() {
        userLoginService.offline();
    }

}
